package com.ideaaedi.log4j2.defender.strategy;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * (non-javadoc)
 *
 * @author JustryDeng
 * @since 2021/7/25 15:29:22
 */
@Component
public class DemoPatternStrategyProvider implements RegexDefenderStrategyProvider {
    
    private static final Pattern ACCOUNT_PATTERN = Pattern.compile("account\\s*=\\s*[a-zA-Z0-9\u4e00-\u9fa5!@#$+%^&*(){}|:\"?.<>/'\\\\\\-_`。；！]*");
    
    private static final Pattern EMAIL_PATTERN = Pattern.compile("mail\\s*=\\s*[a-zA-Z0-9\u4e00-\u9fa5!@#$+%^&*(){}|:\"?.<>/'\\\\\\-_`。；！]*");
    
    private static final Pattern ENGLISH_NAME_PATTERN = Pattern.compile("englishName\\s*=\\s*[a-zA-Z0-9\u4e00-\u9fa5!@#$+%^&*(){}|:\"?.<>/'\\\\\\-_`。；！]*");
    
    private static final Pattern NAME_PATTERN = Pattern.compile("name\\s*=\\s*[a-zA-Z0-9\u4e00-\u9fa5!@#$+%^&*()|:\"?.<>/'\\\\\\-_`。；！]*");
    
    private static final Pattern OTHER1_PATTERN = Pattern.compile("name\\s*\":\"\\s*[a-zA-Z0-9\u4e00-\u9fa5!@#$+%^&*()|:\"?.<>/'\\\\\\-_`。；！]*");
    
    private static final Pattern OTHER2_PATTERN = Pattern.compile("account\\s*\":\"\\s*[a-zA-Z0-9\u4e00-\u9fa5!@#$+%^&*()|:\"?.<>/'\\\\\\-_`。；！]*");
    
    @Override
    public Map<Pattern, DefenderStrategy> provideRegexStrategyMap() {
        Map<Pattern, DefenderStrategy> map = new HashMap<>(8);
        map.put(ACCOUNT_PATTERN, SimpleDefenderStrategy.ACCOUNT_NO);
        map.put(EMAIL_PATTERN, SimpleDefenderStrategy.EMAIL);
        map.put(ENGLISH_NAME_PATTERN, SimpleDefenderStrategy.NAME);
        map.put(NAME_PATTERN, SimpleDefenderStrategy.NAME);
        map.put(OTHER1_PATTERN, SimpleDefenderStrategy.NAME);
        map.put(OTHER2_PATTERN, SimpleDefenderStrategy.ACCOUNT_NO);
        return map;
    }
}
